using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public static class ZTool {
    /// <summary>
    /// 查找子物体，按名称查找
    /// </summary>
    /// <param name="parent">父物体的Transform</param>
    /// <param name="name">子物体的名称</param>
    /// <returns>返回找到的子物体的Transform，如果没有找到则返回null</returns>
    public static Transform FindChildByName(this Transform parent, string name)
    {
        // 遍历所有子物体
        foreach (Transform child in parent)
        {
            if (child.name == name)
            {
                return child;
            }

            // 如果子物体有子物体，递归查找
            Transform found = FindChildByName(child, name);
            if (found != null)
            {
                return found;
            }
        }
        
        // 没有找到指定名称的子物体
        return null;
    }
    
}


